package net.youball.utils.init;

import java.lang.reflect.Field;
import java.util.Iterator;
import java.util.Properties;
import java.util.Map.Entry;

import net.youball.utils.Log;
import net.youball.utils.StringUtils;


public class LoadConfig {

	private LoadConfig(){
		
	}
	
	public static boolean loadConfig(){
		Properties p=new Properties();
		try{
		p.load(LoadConfig.class.getClassLoader().getResourceAsStream("net/youball/conf/othe/Config.properties"));
		int size=p.size()/2;
		for(int i=0;i<size;i++){
			Properties p1=new Properties();
			Class c=Class.forName(p.get(i+"class").toString());
			p1.load(LoadConfig.class.getClassLoader().getResourceAsStream(p.get(i+"path").toString()));
			Iterator<Entry<Object, Object>>  set= p1.entrySet().iterator();
			while(set.hasNext()){
				Entry<Object, Object> ent= set.next();
				Field f=c.getField(ent.getKey().toString());
				if(StringUtils.compareNumber(ent.getValue().toString()))
					f.set(null, Integer.parseInt(ent.getValue().toString()));
			}		
		}
		}catch(Exception e){
			e.printStackTrace();
			Log.sendError("application load config error", e);
			return false;
		}
		return true;
	}
}
